<template>
    <div>
        <el-dialog :title="placeForm.title" :visible.sync="dialogFormVisible" width="60%">
            <el-form :model="placeForm">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="id">
                            <el-input v-model="placeForm.id" autocomplete="off" style="width: 75%" :disabled="true" placeholder="自动生成"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="地点名称">
                            <el-input v-model="placeForm.placeName" autocomplete="off" style="width: 75%" :disabled="placeForm.title === '查看地点信息'" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="工厂名称">
                            <el-input v-model="placeForm.factoryName" autocomplete="off" style="width: 75%" :disabled="placeForm.title === '查看地点信息'" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注">
                            <el-input v-model="placeForm.comment" autocomplete="off" style="width: 90%" type="textarea"
                                      :rows="2" :disabled="placeForm.title === '查看地点信息'" placeholder="请输入"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="创建时间">
                            <el-input v-model="placeForm.createTime" autocomplete="off" style="width: 75%" :disabled="true" placeholder="自动生成"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="save()">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
  import {apiDefaultErrorHandler} from "../../../api/base";
  import workPlaceApi from "../../../api/work/workPlace";

  export default {
    name: "custom",
    props: {
      placeForm: {
        title: '',
        id: '',
        placeName: '',
        factoryName: '',
        comment: '',
        createTime: ''
      },
    },
    data() {
      return {
        dialogFormVisible: false,
      }
    },
    methods: {
      showDialog() {
        this.dialogFormVisible = true
      },
      // 保存数据
      save() {
        workPlaceApi.save(this.placeForm).then(({ data }) => {
          if (this.$http.isResponseSuccess(data)) {
            this.$message('保存成功!!');
            this.dialogFormVisible = false
            // 触发父组件的children事件，将this.form回传过去
            this.$emit('children')
          } else {
            apiDefaultErrorHandler(data)
          }
        }).catch((ex) => {
          apiDefaultErrorHandler(ex)
        })
      },
    }
  }
</script>

<style>
</style>